package com.eorchis.module.modules.ui.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.eorchis.core.log4j.ILog4jManager;
import com.eorchis.core.page.commond.JSONObject;
import com.eorchis.core.springext.mvc.SessionConstant;
import com.eorchis.module.core.domain.HTMLTag;
import com.eorchis.module.department.domain.Department;
import com.eorchis.module.modules.domain.Resource;
import com.eorchis.module.modules.domain.ResourceCondition;
import com.eorchis.module.modules.domain.returnobj.ResourceObject;
import com.eorchis.module.modules.service.IResourceService;
import com.eorchis.module.role.domain.Role;
import com.eorchis.module.role.domain.RoleCondition;
import com.eorchis.module.role.service.IRoleService;
import com.eorchis.module.trainingclass.service.ITrainingClassService;

/**
 * TopController Title: TopController<br>
 * Description: top页面controller<br>
 * Company: ORCHIS<br>
 * Copyright @ 2011 ORCHIS .All rights reserved.<br>
 * 
 * @author HuangS
 * @createDate Sep 13, 2011
 * @version $Revision: 1.5 $
 */
@Controller
@RequestMapping(value = TopController.modulePath)
public class TopController {

	// 模块根路径
	public static final String modulePath = "";

	// @Autowired
	// @Qualifier("null")
	// "com.eorchis.module.role.service.impl.RoleResourceServiceImpl")
	// private IRoleResourceService roleResourceService;

	@Autowired
	@Qualifier("com.eorchis.module.role.service.impl.RoleServiceImpl")
	private IRoleService roleService;

	// 初始化日志接口
	@Autowired
	@Qualifier("com.eorchis.core.log4j.impl.Log4jManager")
	private ILog4jManager log4jManager;

	@Autowired
	@Qualifier("com.eorchis.module.modules.service.impl.ResourceServiceImpl")
	private IResourceService resourceService;

	// 培训班信息接口
	@Autowired
	@Qualifier("com.eorchis.module.trainingclass.service.impl.TrainingClassServiceImpl")
	private ITrainingClassService trainingClassService;

	/**
	 * 查找session中用户拥有的角色(首次刷新)
	 * 
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date Sep 13, 2011
	 */
	@RequestMapping(value = "/listTop")
	public String listTop(Model model, HttpServletRequest request) throws Exception {
		HttpSession session = request.getSession();
		String roleCode = request.getParameter("curRoleMC");
		String deptID = request.getParameter("curScopeMC");
		if (roleCode != null && !"".equals(roleCode) && !"null".equals(roleCode)) {
			model.addAttribute("roleCode", roleCode);
		}
		if ((roleCode != null && !"".equals(roleCode) && !"null".equals(roleCode)) && (deptID != null && !"".equals(deptID))) {
			// 根据角色得到相应的管理范围列表
			List<Department> scopeList = getScopeListByCurrentRole(session, roleCode);
			// 得到当前选择的管理范围并放置到session中
			for (Department casDepartment : scopeList) {
				if (deptID.equals(casDepartment.getDeptID())) {
					session.setAttribute("currentScope", casDepartment);
					break;
				}
			}
			model.addAttribute("deptList", scopeList);
			model.addAttribute("deptID", deptID);
		}

		return TopController.modulePath + "/top.jsp";
	}

	/**
	 * 获取角色集合
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date 2012-12-4
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/findRoleList")
	public @ResponseBody
	JSONObject findRoleList(HttpServletRequest request) throws Exception {
		JSONObject object = new JSONObject();
		HttpSession session = request.getSession();
		List<com.eorchis.module.security.cas.domain.Role> list = (List<com.eorchis.module.security.cas.domain.Role>) session.getAttribute(SessionConstant.ROLES);
		List<HTMLTag> data = new ArrayList<HTMLTag>();
		if (list != null) {
			for (com.eorchis.module.security.cas.domain.Role casRole : list) {
				HTMLTag tag = new HTMLTag();
				tag.setTag(HTMLTag.TAG_OPTION);
				tag.setHtml(casRole.getRoleName());
				tag.setValue(casRole.getRoleCode());
				data.add(tag);
			}
			if (list.size() == 1) {
				data.get(0).setSelected(HTMLTag.SELECT_TRUE);
			}
			object.setSuccess(true);
		} else {
			object.setSuccess(false);
			object.setMsg("roles is null");
		}
		object.setData(data);
		return object;
	}

	/**
	 * 获取管理范围集合
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date 2012-12-4
	 */
	@RequestMapping(value = "/findScopeList")
	public @ResponseBody
	JSONObject findScopeList(HttpServletRequest request) throws Exception {
		JSONObject object = new JSONObject();
		HttpSession session = request.getSession();
		String roleCode = request.getParameter("roleCode");
		// 选择角色时清空管理范围
		session.removeAttribute(SessionConstant.CURRENT_ROLE);
		// 选择角色时清空角色
		session.removeAttribute(SessionConstant.CURRENT_SCOPE);
		if (roleCode == null || "".equals(roleCode)) {
			object.setSuccess(false);
			object.setMsg("未选择角色");
			return object;
		}
		List<Department> list = this.getScopeListByCurrentRole(session, roleCode);
		List<HTMLTag> data = new ArrayList<HTMLTag>();
		for (Department casDepartment : list) {
			HTMLTag tag = new HTMLTag();
			tag.setTag(HTMLTag.TAG_OPTION);
			tag.setHtml(casDepartment.getDeptName());
			tag.setValue(casDepartment.getDeptID().toString());
			data.add(tag);
		}
		if (list.size() == 1) {
			data.get(0).setSelected(HTMLTag.SELECT_TRUE);
		}
		object.setSuccess(true);
		object.setData(data);
		return object;
	}

	/**
	 * 查找session中相应角色所拥有的管理范围
	 * 
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date Sep 13, 2011
	 */
	@RequestMapping(value = "/findScope")
	public @ResponseBody
	List<Department> findScope(Model model, HttpServletRequest request) throws Exception {
		List<Department> scopeList = new ArrayList<Department>();
		HttpSession session = request.getSession();
		try {
			String roleCode = request.getParameter("roleCode");
			// 选择角色时清空管理范围
			session.removeAttribute("currentScope");
			// 选择角色时清空角色
			session.removeAttribute("currentRole");
			if (roleCode == null || "".equals(roleCode)) {
				return null;
			}
			// 根据角色得到相应的管理范围列表
			scopeList = getScopeListByCurrentRole(session, roleCode);
			return scopeList;
		} catch (Exception e) {
			log4jManager.saveExceptionLog(getClass().getName(), "findScope", "获取管理范围时出错", e);
			session.removeAttribute("currentScope");
			session.removeAttribute("currentRole");
			Department cs = new Department();
			cs.setDeptName("异常:" + e.getMessage());
			cs.setDeptCode("false");
			scopeList.add(cs);
			return scopeList;
		}
	}

	/**
	 * 根据角色得到相应的管理范围列表
	 * 
	 * @param session
	 * @param roleCode
	 * @return
	 * @author HuangS
	 * @date Sep 14, 2011
	 */
	@SuppressWarnings("unchecked")
	private List<Department> getScopeListByCurrentRole(HttpSession session, String roleCode) {
		List<Department> scopeList = new ArrayList<Department>();
		List<com.eorchis.module.security.cas.domain.Role> roleList = (List<com.eorchis.module.security.cas.domain.Role>) session.getAttribute(SessionConstant.ROLES);
		if (roleList != null && roleList.size() > 0) {
			// 得到当前选择的角色并放置到session中并返回当前角色的管理范围列表
			for (com.eorchis.module.security.cas.domain.Role casRole : roleList) {
				if (casRole.getRoleCode().equals(roleCode)) {
					session.setAttribute("currentRole", casRole);
					scopeList = casRole.getScopes();
					return scopeList;
				}
			}
		}
		return scopeList;
	}

	/**
	 * 得到menu菜单
	 * 
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date Sep 14, 2011
	 */
	@RequestMapping(value = "/findMenu")
	public @ResponseBody
	List<ResourceObject> findMenu(HttpServletRequest request) throws Exception {
		// JSON结果集封装
		// TopResultInfo resultInfo = new TopResultInfo();
		List<ResourceObject> resultList = new ArrayList<ResourceObject>();
		HttpSession session = request.getSession();
		try {
			// 选择的角色
			String roleCode = request.getParameter("roleCode");
			// 选择的管理范围ID
			String deptID = request.getParameter("deptID");
			// 选择管理范围时清空管理范围
			session.removeAttribute(SessionConstant.CURRENT_SCOPE);
			if (deptID == null || "".equals(deptID)) {
				// 选择管理范围为空时清空角色
				session.removeAttribute(SessionConstant.CURRENT_ROLE);
				return null;
			}
			// 根据角色得到相应的管理范围列表
			List<Department> scopeList = this.getScopeListByCurrentRole(session, roleCode);
			// 得到当前选择的管理范围并放置到session中
			for (Department casDepartment : scopeList) {
				if (deptID.equals(casDepartment.getDeptID())) {
					session.setAttribute("currentScope", casDepartment);
					break;
				}
			}

			//动态获取权限，如果干教处键班承办单位为其他单位时，则其他单位登录时获得一级管理菜单	byRongSL
			/*if (!RoleConstants.ROLE_CODE_GJC_ADMIN.equals(roleCode)) {
				if(trainingClassService.isGJCChoiceUndertake(deptID)!=0)
					roleCode = RoleConstants.ROLE_CODE_GJC_ADMIN_TEMP;
			}*/
			// 根据角色编码查询角色信息
			RoleCondition roleCondition = new RoleCondition();
			roleCondition.setQueryRoleCode(roleCode);
			roleCondition.setSearchActiveState(Role.IS_ACTIVE_Y);
			List<Role> roleList = roleService.getRoleByRoleCode(roleCondition);
			// 根据角色ID查询相应的角色-资源信息
			// RoleResourceCondition condition = new RoleResourceCondition();

			ResourceCondition resourceCondition = new ResourceCondition();

			resourceCondition.setSearchActiveState(com.eorchis.module.modules.domain.Resource.IS_ACTIVE_Y.toString());
			// 不翻页查询
			resourceCondition.setRows(-1);
			resourceCondition.setStart(-1);
			if (roleList != null && roleList.size() > 0) {
				if (roleList.get(0).getRoleID() != null && !"".equals(roleList.get(0).getRoleID())) {
					// condition.setQueryRoleID(roleList.get(0).getRoleID());
					resourceCondition.setRoleIds(new String[] { roleList.get(0).getRoleID() });
				}
			} else {
				log4jManager.saveExceptionLog(getClass().getName(), "findMenu", "roleList is null ", new Exception("roleList is null"));
			}
			// 当前用户角色用户的资源
			List<com.eorchis.module.modules.domain.Resource> allResourceList = resourceService.findList(resourceCondition);
			session.setAttribute(SessionConstant.RESOURCE_SCOPE, allResourceList);

			// 根据角色查询一级资源集合
			resourceCondition.setQueryResourceParentID("-1");
			List<com.eorchis.module.modules.domain.Resource> parentList = resourceService.findRoleList(resourceCondition);
			// 拼装资源树形结构
			for (com.eorchis.module.modules.domain.Resource parentResource : parentList) {
				// 将当前角色下的资源信息，根绝当前登录人有用的资源权限，封装到ResourceObject中
				ResourceObject menuResource = buildMenuResource(allResourceList, parentResource);
				resultList.add(menuResource);
				//
				resourceCondition.setSearchIsContainLeapnode(String.valueOf(Resource.IS_CONTAIN_LEAPNODE_Y));
				buildSubMenu(menuResource.getChildren(), allResourceList, resourceCondition, parentResource);
			}

			// List<RoleResourceMenuBean> result =
			// roleResourceService.getRoleResourceByRoleId(condition);

			// 父级菜单列表
			// List<RoleResourceMenuBean> parentList = new
			// ArrayList<RoleResourceMenuBean>();
			// 子级菜单列表
			// List<RoleResourceMenuBean> sonList = new
			// ArrayList<RoleResourceMenuBean>();

			// for (RoleResourceMenuBean roleResourceMenuBean : result) {
			// if (roleResourceMenuBean.getParentID() == -1) {
			// parentList.add(roleResourceMenuBean);
			// } else if (roleResourceMenuBean.getParentID() != -1 &&
			// roleResourceMenuBean.getParentID() != -2) {
			// sonList.add(roleResourceMenuBean);
			// }
			// }
			// resultInfo.setParentMenu(parentList);
			// resultInfo.setSonMenu(sonList);
			// resultInfo.setIsSuccess("success");
			// 临时测试帐号
			// String[] testLoginId=new
			// String[]{"839999777","811999777","A19999776","A29999776","A39999776","VIP000126"};
			// // String[] testLoginId=new
			// String[]{"315000126","315000124","VIP000126"};
			// User cu=(User)
			// request.getSession().getAttribute(SessionConstant.USER_INFO);
			// boolean flag=true;
			// for(String t:testLoginId){
			// if(cu.getLoginID().equals(t)){
			// flag=false;
			// }
			// }
			// if(flag==true){
			// if(!roleCode.equals(RoleConstants.ROLE_CODE_DW_ADMIN)){
			// resultList.remove(6);
			// resultList.remove(0);
			// resultList.get(0).getChildren().remove(0);
			// }else{
			// resultList.remove(4);
			// resultList.remove(0);
			// }
			// }
			return resultList;
		} catch (Exception e) {
			log4jManager.saveExceptionLog(getClass().getName(), "findMenu", "获取菜单时出错", e);
			session.removeAttribute("currentScope");
			session.removeAttribute("currentRole");
			// resultInfo.setIsSuccess("false");
			// resultInfo.setFailReason(e.getMessage());
			return resultList;
		}
	}

	/**
	 * 根据用户的角色获取用户资源
	 * 
	 * @param model
	 * @param request
	 * @return
	 * @throws Exception
	 * @author XiangBin
	 * @date Jul 31, 2012
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/findRoleMenu")
	public @ResponseBody
	List<ResourceObject> findRolesMenu(HttpServletRequest request) throws Exception {
		// JSON结果集封装
		HttpSession session = request.getSession();
		List<ResourceObject> resultList = new ArrayList<ResourceObject>();
		try {
			// 获取角色所对应的资源范围
			List<com.eorchis.module.modules.domain.Resource> allResourceList = (List<com.eorchis.module.modules.domain.Resource>) session.getAttribute("resourceScopes");
			// 获取用户角色信息
			List<Role> roles = (List<Role>) session.getAttribute("roles");
			if (roles != null && roles.size() > 0) {
				// 获取用户角色对应拥有的资源
				String[] roleIds = new String[roles.size()];
				if (roles != null && roles.size() > 0) {
					for (int i = 0; i < roles.size(); i++) {
						Role role = roles.get(i);
						roleIds[i] = role.getRoleID();
					}
				}
				// 根据角色查询一级资源集合
				ResourceCondition condition = new ResourceCondition();
				condition.setQueryResourceParentID("-1");
				condition.setRoleIds(roleIds);
				condition.setRows(-1);
				condition.setStart(-1);
				condition.setSearchActiveState(com.eorchis.module.modules.domain.Resource.IS_ACTIVE_Y.toString());
				// 根据当前登录人角色查询根级菜单
				List<com.eorchis.module.modules.domain.Resource> parentList = resourceService.findRoleList(condition);
				for (com.eorchis.module.modules.domain.Resource parentResource : parentList) {
					// 将当前角色下的资源信息，根绝当前登录人有用的资源权限，封装到ResourceObject中
					ResourceObject menuResource = buildMenuResource(allResourceList, parentResource);
					resultList.add(menuResource);
					//
					condition.setSearchIsContainLeapnode(String.valueOf(Resource.IS_CONTAIN_LEAPNODE_Y));
					buildSubMenu(menuResource.getChildren(), allResourceList, condition, parentResource);
				}
			}
		} catch (Exception e) {
			log4jManager.saveExceptionLog(getClass().getName(), "findMenu", "获取菜单时出错", e);
		}
		mergeResourceList(resultList);
		return resultList;
	}

	/**
	 * 合并重复的资源 主要是因为如果当多个角色包含了重叠的资源，且这写角色被分配给同一个用户时，会导致界面的左侧菜单出现重复的菜单项。
	 * 
	 * @param resultList
	 */
	private void mergeResourceList(List<ResourceObject> resultList) {
		List<ResourceObject> repeatedResources = new ArrayList<ResourceObject>();// 保存重复的资源，用于到遍历结束后将其从资源list中删除掉。
		/*
		 * 循环遍历资源list自身，遍历是否有重复的资源（资源id一致），如果有重复的资源，则将其保存在repeatedResources中，
		 * 并将被重复的资源的所有子资源 加入到已存在的资源中。
		 */
		for (int i = 0; i < resultList.size(); i++) {
			ResourceObject resourceObject = resultList.get(i);
			// 如果当前被循环的对象是重复的资源，则无需在做处理，直接跳过。
			if (repeatedResources.contains(resourceObject)) {
				continue;
			}
			for (int j = i + 1; j < resultList.size(); j++) {
				ResourceObject _resourceObject = resultList.get(j);
				// 如果资源重复（资源id一致），则将其所有的子资源加入到当前资源中。
				if (resourceObject.getResourceID().equals(_resourceObject.getResourceID())) {
					List<ResourceObject> childrenResourceList = resourceObject.getChildren();
					childrenResourceList.addAll(_resourceObject.getChildren());
					repeatedResources.add(_resourceObject);
					// 将append的所有子资源再次进行 merge处理，实现所有递归的合并。
					mergeResourceList(childrenResourceList);
				}
			}
		}
		// 由于重复资源的所有子资源已经被处理，可以放心的将重复资源删除掉。
		resultList.removeAll(repeatedResources);
	}

	/**
	 * 构建二级及其以下所有子菜单
	 * 
	 * @param resultList
	 *            当前资源下的所有子资源的集合
	 * @param allResourceList
	 *            当前登录人有权访问的所有资源
	 * @param condition
	 *            查询条件对象，因为要经常变化被查询的资源ID，所以传递进来作为参数。
	 * @param parentResource
	 *            系统资源，该资源用于判断在其下是否有可访问的子资源，如果有，
	 *            则封装到返回值对象ResourceObject的children集合属性中。
	 *            parentResource也用于填充返回对象ResourceObject的基本信息，如资源名称，资源url等。
	 * @throws Exception
	 */
	private void buildSubMenu(List<ResourceObject> resultList, List<com.eorchis.module.modules.domain.Resource> allResourceList, ResourceCondition condition,
			com.eorchis.module.modules.domain.Resource parentResource) throws Exception {
		if (parentResource.getIsContainLeapnode().intValue() == Resource.IS_CONTAIN_LEAPNODE_Y) {
			condition.setQueryResourceParentID(parentResource.getResourceID());
			List<com.eorchis.module.modules.domain.Resource> menuList = resourceService.findRoleList(condition);
			for (com.eorchis.module.modules.domain.Resource menuResource : menuList) {
				ResourceObject subMenuResource = buildMenuResource(allResourceList, menuResource);

				// 判断当前subMenuResource对象是否已经在resultList中包含，如果包含，则将该对象重新覆盖到resultList中，否则新增*****
				// 因为上面的buildMenuResource方法无论菜单还是功能点都会加入进ResourceObject的children里，所以这里需要进行判断是否已经存在。
				boolean resourceExist = false;// 该属性用于判断在之前是否已经将指定资源加入到resultList中
				for (int i = 0; i < resultList.size(); i++) {
					ResourceObject _resourceObject = resultList.get(i);
					if (_resourceObject.getResourceID().equals(subMenuResource.getResourceID())) {
						resultList.set(i, subMenuResource);
						resourceExist = true;
						break;
					}
				}
				if (!resourceExist) {
					resultList.add(subMenuResource);
				}
				// *****
				buildSubMenu(subMenuResource.getChildren(), allResourceList, condition, menuResource);
			}
		}
	}

	/**
	 * 构建资源对象ResourceObject，用于最终返回给页面生成JSON使用。
	 * 该对象中包含了指定角色parentResource下的所有登录人拥有的资源（菜单资源和功能点资源）。
	 * 
	 * @param allResourceList
	 *            当前登录人有权访问的所有资源
	 * @param parentResource
	 *            系统资源，该资源用于判断在其下是否有可访问的子资源，如果有，
	 *            则封装到返回值对象ResourceObject的children集合属性中。
	 *            parentResource也用于填充返回对象ResourceObject的基本信息，如资源名称，资源url等。
	 * @return ResourceObject对象，用于最终返回给页面生成JSON使用。其中包含了parentResource大部分信息，
	 *         也包含了所有可访问的子资源信息。
	 */
	private ResourceObject buildMenuResource(List<com.eorchis.module.modules.domain.Resource> allResourceList, com.eorchis.module.modules.domain.Resource parentResource) {
		ResourceObject rObject = new ResourceObject();
		rObject.setResourceName(parentResource.getResourceName());
		rObject.setResourceID(parentResource.getResourceID());
		rObject.setUrl(parentResource.getUrl());
		rObject.setIconCls(parentResource.getIconCls());
		List<ResourceObject> sonList = new ArrayList<ResourceObject>();

		for (com.eorchis.module.modules.domain.Resource sonResource : allResourceList) {
			if (sonResource.getIsMenu().intValue() == com.eorchis.module.modules.domain.Resource.IS_MENU_N) {
				continue;
			}
			if (parentResource.getResourceID().equals(sonResource.getParentID())) {
				ResourceObject sonObject = new ResourceObject();
				sonObject.setResourceName(sonResource.getResourceName());
				sonObject.setResourceID(sonResource.getResourceID());
				sonObject.setUrl(sonResource.getUrl());
				sonObject.setIconCls(sonResource.getIconCls());
				sonList.add(sonObject);
			}
		}
		rObject.setChildren(sonList);
		// resultList.add(rObject);
		return rObject;
	}

	/**
	 * 获取当前登陆人的功能权限
	 * 
	 * @param request
	 * @return
	 * @throws Exception
	 * @author HuangS
	 * @date Aug 23, 2012
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/findUserPermissions")
	public @ResponseBody
	JSONObject findUserPermissions(HttpServletRequest request) throws Exception {
		HttpSession session = request.getSession();
		JSONObject result = (JSONObject) session.getAttribute(SessionConstant.CURRENT_PERMISSIONS);
		if (result == null) {
			result = new JSONObject();
			// 获取角色所对应的资源范围
			List<com.eorchis.module.modules.domain.Resource> userResourceList = (List<com.eorchis.module.modules.domain.Resource>) session.getAttribute(SessionConstant.RESOURCE_SCOPE);
			if (userResourceList == null) {
				result.setSuccess(false);
				return result;
			}
			ResourceCondition resourceCondition = new ResourceCondition();
			resourceCondition.setSearchActiveState(Resource.IS_ACTIVE_Y.toString());
			// 不翻页查询
			resourceCondition.setRows(-1);
			resourceCondition.setStart(-1);
			// 查询全部的启用资源
			List<com.eorchis.module.modules.domain.Resource> allResourceList = resourceService.findList(resourceCondition);
			// 临时map变量，方便快速查找
			Map<String, com.eorchis.module.modules.domain.Resource> tempMap = new HashMap<String, com.eorchis.module.modules.domain.Resource>();
			List<com.eorchis.module.modules.domain.Resource> tempList = new ArrayList<com.eorchis.module.modules.domain.Resource>();
			for (com.eorchis.module.modules.domain.Resource resource : allResourceList) {
				// 去掉根及1级目录
				if (!"-1".equals(resource.getParentID()) && !"-2".equals(resource.getParentID())) {
					tempMap.put(resource.getResourceID(), resource);
				}
			}
			// 循环获取用户已选资源,从全部资源中删除
			for (com.eorchis.module.modules.domain.Resource userResource : userResourceList) {
				tempList.add(tempMap.get(userResource.getResourceID()));
			}
			// 去除用户已选资源
			allResourceList.removeAll(tempList);

			Map<String, List<String>> resultData = new HashMap<String, List<String>>();
			// 循环未设置权限的资源，拼装结果
			for (com.eorchis.module.modules.domain.Resource resource : allResourceList) {
				// 功能点
				if (resource.getIsMenu().equals(com.eorchis.module.modules.domain.Resource.IS_MENU_N)) {
					com.eorchis.module.modules.domain.Resource parentResource = tempMap.get(resource.getParentID());
					if (parentResource != null) {
						List<String> funcList = resultData.get(parentResource.getUrl());
						if (funcList == null) {
							funcList = new ArrayList<String>();
						}
						funcList.add(resource.getUrl());
						resultData.put(parentResource.getUrl(), funcList);
					}
				}
			}

			result.setData(resultData);
			result.setSuccess(true);
			session.setAttribute(SessionConstant.CURRENT_PERMISSIONS, result);
		}

		return result;
	}

}
